package com.android.plc.ui.control;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.android.plc.CONST;
import com.android.plc.CONST.COMMAND;
import com.android.plc.R;

public class NormalControl extends BaseControl implements OnClickListener
{
	public static final String TAG = "NormalControl";
	public ImageButton mOnBtn;
	public ImageButton mOffBtn;

	public NormalControl(Context context, ViewGroup view, int res_id)
	{
		super(context, view, res_id);
	}

	public NormalControl(Context context, ViewGroup view)
	{
		super(context, view, R.layout.control_normal);
	}

	@Override
	public void initView(ViewGroup view)
	{
		mOnBtn = (ImageButton) view.findViewById(R.id.btn_on);
		mOffBtn = (ImageButton) view.findViewById(R.id.btn_off);

		mOnBtn.setOnClickListener(this);
		mOffBtn.setOnClickListener(this);
		
	}

	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btn_on:
			sendCommand(COMMAND.ON, CONST.DEF_DATA, 0);
			break;
		case R.id.btn_off:
			sendCommand(COMMAND.OFF, 0, 0);
			break;
		default:
			break;
		}
	}

	@Override
	public void onReceive(int command, int data1, int data2)
	{
		if (command == COMMAND.ON || command == COMMAND.STATUSON)
		{
			mOnBtn.setAlpha(OFF_ALPHA);
			mOffBtn.setAlpha(ON_ALPHA);
		} else if (command == COMMAND.OFF || command == COMMAND.STATUSOFF)
		{
			mOnBtn.setAlpha(ON_ALPHA);
			mOffBtn.setAlpha(OFF_ALPHA);
		}
	}

}
